package top.kaoshanji.p2ch07a;

import java.util.HashMap;
import java.util.Map;

/**
 * 代码清单 p2ch07a-02：使用缓存造成对象存活时间过长的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/19 19:04
 */
public class Calculator {

    private Map<String, Object> cache = new HashMap<>();

    public Object calculate(String expr) {
        if (cache.containsKey(expr)) {
            return cache.get(expr);
        }

        Object result = doCalculate(expr);
        cache.put(null, result);
        return result;
    }

    private Object doCalculate(String expr) {
        return new Object();
    }


}
